/**
 * TimeStamp.java
 *
 * A very simple class used by many classes like
 * Sprites,GameMap for timming their actions.
 *
 * @author Somanath
 * @version 1.1 (last updated 13/9/02)
 *
 * class Dependencies: None
 */

package gamepack;

public class TimeStamp {

	public	long interval;
	public long stamp;

    private static long getTime() {
           return Game.getTime();
    }

	public TimeStamp() {
		interval = 250 * 1000000L;
		stamp=getTime();
	}

	public void setInterval(int interval)
	{	this.interval = interval * 1000000L;	}

	public TimeStamp(int interval) {
		this.interval = interval * 1000000L;
		stamp=getTime();
	}

	public TimeStamp(int interval,boolean setFlag) {
		this.interval = interval * 1000000L;

        // Check this... should it be interval+1 ?
		if( setFlag ) 	stamp = getTime()-interval-1;
		else 			stamp = getTime();
	}

	public boolean elapsed() {
		long curTime = getTime();
		if( curTime > (stamp+interval) ) {
			stamp = curTime;
			return true;
		}
		else
			return false;
	}





	/**
	 * @return  true if t milliseconds have elapsed since the
	 	"last call to this method when it returned true".
	 */
	public boolean elapsed(int t) {

		long curTime = getTime();
		if( curTime > stamp+(t*1000000L) ) {
			stamp = curTime;
			return true;
		}
		else
			return false;
	}


	/** All future calls to elapsed() will not return true until
		"interval" milliseconds have elapsed since this call.
		("interval" milliseconds is specified while creating the object) */
	public void reset() {	stamp = getTime();	}

	/**  Ensures that the next call to elapsed() will return true */
	public void set()	{	stamp = getTime()-interval-1;	}
}